import * as React from 'react';
import * as moment from 'moment';
import { Link } from 'react-router';
import { Popconfirm } from 'antd';
import { AdsManager } from './Manager';

export function createColumns(instance: AdsManager) {
    return [
        // {
        //     title: '广告位ID',
        //     dataIndex: 'id',
        // },
        {
            title: '广告位名称',
            dataIndex: 'name',
        },
        {
            title: '创建日期',
            dataIndex: 'createdAt',
            render: (timestamp: number) => {
                return <span>{moment(timestamp).format("YYYY-MM-DD HH:mm:ss")}</span>;
            }
        },
        {
            title: '创建者',
            dataIndex: 'createdBy',
        },
        {
            title: '最后编辑日期',
            dataIndex: 'updatedAt',
            render: (timestamp: number) => {
                return <span>{moment(timestamp).format("YYYY-MM-DD HH:mm:ss")}</span>;
            }
        },
        {
            title: '最后编辑者',
            dataIndex: 'updatedBy',
        },
        {
            title: '操作',
            render: (data, record, index) => {
                return <span>
                    <Link to={`/content/assets/ads/edit/${data.id}`}>编辑</Link>
                    <span className="ant-divider" />
                    <Popconfirm title="确认删除这条记录？" onConfirm={() => instance.deleteItem(data.id)}>
                        <a>删除</a>
                    </Popconfirm>
                </span>;
            }
        }
    ];
}